<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/common/header.jsp" %>
<%String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %>
<a href="" title="权限管理——用户管理"></a>
<script type="text/javascript" src="../../js/userState.js">
</script>
<script type="text/javascript">
    
    Ext.onReady(function(){
        Ext.BLANK_IMAGE_URL = '<c:url value="/js/ext/images/default/s.gif"/>';
        // ---------------------- Global vars and functions------------------------------
        Ext.SERVER = '<c:url value="/"/>';
        function getFullPath(obj){
            if (obj) {
                //ie
                if (window.navigator.userAgent.indexOf("MSIE") >= 1) {
                    alert(obj.select());
                    return document.selection.createRange().text;
                }
                //firefox
                else 
                    if (window.navigator.userAgent.indexOf("Firefox") >= 1) {
                        if (obj.files) {
                            return obj.files.item(0).getAsDataURL();
                        }
                        return obj.value;
                    }
                return obj.value;
            }
        }
        // --------------- detail form -------------------
        var detailFrom_userCertificateType = new Ext.form.ComboBox({
            name: 'userCertificateType',
            hiddenName: 'userCertificateType',
            fieldLabel: '证件类型',
            typeAhead: true,
            width: 70,
            msgTarget: 'side',
            triggerAction: 'all',
            lazyRender: true,
            mode: 'local',
            value: '0',
            store: new Ext.data.ArrayStore({
                id: 'key',
                fields: ['key', 'value'],
                data: [['0', '身份证'], ['1', '学生证'], ['2', '户口簿'], ['3', '护照'], ['4', '通行证'], ['5', '士兵证']]
            }),
            valueField: 'key',
            displayField: 'value'
        });
        
        var detailFrom_userType = new Ext.form.ComboBox({
            name: 'userType',
            hiddenName: 'userType',
            fieldLabel: '用户类型',
            readOnly: true,
            disabled: true,
            typeAhead: true,
            triggerAction: 'all',
            lazyRender: true,
            mode: 'local',
            value: '0',
            store: new Ext.data.ArrayStore({
                id: 'key',
                fields: ['key', 'value'],
                data: [['0', '普通教师'], ['1', '管理员'], ['2', '学校领导'], ['3', '部门领导'], ['5', '学生']]
            }),
            valueField: 'key',
            displayField: 'value'
        });
        
        
        
        // 证件验证
        Ext.apply(Ext.form.VTypes, {
            IDCard: function(val, field){
                var type = detailFrom_userCertificateType.getValue();
                if (type == 0) { // 身份证
                    idCard = detailForm.getForm().findField('userCertificateNo').getValue();
                    if (idCard.length == 15 || idCard.length == 18) 
                        return true;
                    return false;
                }
                return true;
            }
        });
        
        // --------------- form and window --------------------
        var detailForm = new Ext.form.FormPanel({
            bodyStyle: 'padding:5px',
            title: '个人信息修改（所有信息仅用户本人可见！）',
            frame: true,
            fileUpload: true,
            buttonAlign: 'left',
            height: 386,
            layout: 'form',
            items: [{
                layout: 'form',
                frame: true,
                labelWidth: 80,
                items: [{
                    layout: 'column',
                    items: [{
                        columnWidth: .5,
                        labelWidth: 80,
                        width: 80,
                        layout: 'form',
                        items: [{
                            name: 'id',
                            inputType: 'hidden',
                            xtype: 'textfield',
                            msgTarget: 'side',
                            fieldLabel: '编号'
                        }, {
                            name: 'readOnly',
                            inputType: 'hidden',
                            xtype: 'textfield',
                            msgTarget: 'side'
                        }, detailFrom_userCertificateType, {
                            name: 'userRealName',
                            xtype: 'textfield',
                            msgTarget: 'side',
                            fieldLabel: '姓名'
                        }, detailFrom_userState, {
                            name: 'e2qSmDepartment',
                            inputType: 'hidden',
                            fieldLabel: '*上级部门id',
                            xtype: 'textfield',
                            id: 'userDepartmentId'
                        }, {
                            name: 'e2qSmDepartmentName',
                            allowBlank: false,
                            fieldLabel: '所属部门',
                            xtype: 'textfield',
                            readOnly: true,
                            disabled: true,
                            id: 'userDepartmentName'
                        }, {
                            name: 'userOfficeFax',
                            xtype: 'textfield',
                            msgTarget: 'side',
                            fieldLabel: '办公传真号码'
                        }, {
                            name: 'userHomePostalCode',
                            xtype: 'textfield',
                            msgTarget: 'side',
                            fieldLabel: '家庭邮政编码'
                        }, {
                            name: 'image',
                            inputType: 'file',
                            fieldLabel: '&nbsp;头像',
                            xtype: 'textfield',
                            id: 'image',
                            autoCreate: {
                                tag: 'input',
                                type: 'file',
                                size: '20',
                                autocomplete: 'off'
                                // onChange: function(){alert('ddd')}
                            },
                            listeners: {
                                blur: function(f){
                                    if (Ext.get('image').dom.value != "") {
                                        if (Ext.isIE7 || Ext.isIE8) {
                                            var image = Ext.get('imagePreview').dom;
                                            var url = 'file:///' + Ext.get('image').dom.value;
                                            image.src = Ext.BLANK_IMAGE_URL;// 覆盖原来的图片
                                            image.filters.item('DXImageTransform.Microsoft.AlphaImageLoader').src = url;
                                        }
                                        if (Ext.isIE6) {
                                            var image = Ext.get('imagePreview').dom;
                                            var url = 'file:///' + Ext.get('image').dom.value;
                                            image.src = Ext.BLANK_IMAGE_URL;// 覆盖原来的图片
                                            image.src = url;
                                        }
                                        if (!Ext.isIE) {
                                            if (window.navigator.userAgent.indexOf("Firefox") >= 1) {
                                                Ext.get('imagePreview').dom.src = getFullPath(Ext.get('image').dom);
                                            }
                                            else {
                                                var image = Ext.get('imagePreview').dom;
                                                var url = 'file:///' + Ext.get('image').dom.value;
                                                image.src = Ext.BLANK_IMAGE_URL;// 覆盖原来的图片
                                                image.src = url;
                                            }
                                        }
                                        
                                    }
                                    
                                }
                            }
                        
                        }]
                    }, {
                        columnWidth: .5,
                        layout: 'form',
                        labelWidth: 80,
                        defaultType: 'textfield',
                        defaults: {
                            width: 130,
                            msgTarget: 'side'
                        },
                        items: [{
                            name: 'userLoginId',
                            readOnly: true,
                            disabled: true,
                            fieldLabel: '用户登录名'
                        }, detailFrom_userType, {
                            name: 'userCertificateNo',
                            fieldLabel: '证件号码',
                            vtype: 'IDCard'
                        }, {
                            name: 'userMobile',
                            fieldLabel: '移动电话号码'
                        }, {
                            name: 'userOfficePhone',
                            fieldLabel: '办公电话号码'
                        }, {
                            name: 'userHomePhone',
                            fieldLabel: '家庭电话号码'
                        }, {
                            fieldLabel: '头像预览',
                            autoCreate: {
                                width: 30,
                                height: 75,
                                tag: 'input',
                                type: 'image',
                                name: 'imagePreview',
                                complete: 'off',
                                style: 'filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=scale);',
                                id: 'imagePreview',
                                src: ''
                            }
                        }]
                    }]
                }, new Ext.form.TextField({
                    id: "userEmail",
                    fieldLabel: "邮箱",
                    allowBlank: false,
                    name: 'userEmail',
                    width: 350
                }), new Ext.form.TextArea({ //TextArea
                    fieldLabel: '说明',
                    name: 'userNotes',
                    labelWidth: 50,
                    width: 350,
                    height: 60,
                    id: 'userNotes'
                }), new Ext.form.Label({
                    html: '用户信息修改说明：<br>  ' +
                    '&nbsp;&nbsp;&nbsp;&nbsp;1、本页面仅用于用户基本信息的维护；<br>' +
                    '&nbsp;&nbsp;&nbsp;&nbsp;2、用户基本信息仅用户本人可以看见；<br>' +
                    '&nbsp;&nbsp;&nbsp;&nbsp;3、部分信息将用于权限系统、短信系统等应用系统。（如：移动电话号码可用于接收学校发的各种信息）'
                })]
            }],
            buttons: [{
                id: 'button',
                name: 'button',
                text: '保存',
                handler: function(){
                    if (detailForm.getForm().isValid()) {
                        detailForm.getForm().submit({
                            url: '<c:url value="/user/userUpdate.do" />',
                            params: {
                                userLoginId: detailForm.getForm().findField("userLoginId").value,
                                userRealName: detailForm.getForm().findField("userRealName").value,
                                userCertificateType: detailForm.getForm().findField("userCertificateType").value,
                                userCertificateNo: detailForm.getForm().findField("userCertificateNo").value,
                                userEmail: detailForm.getForm().findField("userEmail").value
                            },
                            waitTitle: '请等待',
                            waitMsg: '正在处理数据...',
                            timeout: 30,
                            success: function(form, action){
                                function ok(){
                                    detailForm.getForm().load({
                                        url: '<c:url value="/user/userInfo.do"/>',
                                        waitMsg: 'loading...',
                                        success: function(response, action){
                                            text = action.response.responseText;
                                            json = Ext.decode(text);
                                            Ext.get('imagePreview').dom.src = action.result.data.imageUrl;
                                            if (json.mainreadony == 'true') {
                                                detailForm.getForm().findField("userRealName").setDisabled(true);
                                                detailForm.getForm().findField("userCertificateType").setDisabled(true);
                                                detailForm.getForm().findField("userCertificateNo").setDisabled(true);
                                                detailForm.getForm().findField("userEmail").setDisabled(true);
                                            }
                                            if (json.subordination == 'true') {
                                                detailForm.getForm().findField("userOfficeFax").getEl().setDisabled(true);
                                                detailForm.getForm().findField("userHomePostalCode").setDisabled(true);
                                                detailForm.getForm().findField("userMobile").getEl().setDisabled(true);
                                                detailForm.getForm().findField("userOfficePhone").setDisabled(true);
                                                detailForm.getForm().findField("userHomePhone").setDisabled(true);
                                                detailForm.getForm().findField("userNotes").setDisabled(true);
                                                
                                            }
                                            if (json.otherreadony == 'true') {
                                            }
                                            if (json.mainreadony == 'true' && json.subordination == 'true' && json.otherreadony == 'true') {
                                                Ext.getCmp("button").setDisabled(true);
                                            }
                                            //document.getElementById("button").style.display="none";
                                        },
                                        failure: function(){
                                            Ext.Msg.alert('提示', '请先登录！');
                                        }
                                    });
                                };
                                Ext.Msg.alert('提示', '操作成功。', ok);
                            },
                            failure: function(response, action){
                                text = action.response.responseText;
                                json = Ext.decode(text);
                                Ext.Msg.alert('提示', json.message);
                            }
                        });
                    }
                }
            }, {
                text: '重置',
                handler: function(){
                    detailForm.getForm().reset();
                    detailForm.getForm().load({
                        url: '<c:url value="/user/userInfo.do"/>',
                        waitMsg: 'loading...',
                        success: function(response, action){
                            text = action.response.responseText;
                            json = Ext.decode(text);
                            Ext.get('imagePreview').dom.src = action.result.data.imageUrl;
                            if (json.mainreadony == 'true') {
                                detailForm.getForm().findField("userRealName").setDisabled(true);
                                detailForm.getForm().findField("userCertificateType").setDisabled(true);
                                detailForm.getForm().findField("userCertificateNo").setDisabled(true);
                                detailForm.getForm().findField("userEmail").setDisabled(true);
                            }
                            if (json.subordination == 'true') {
                                detailForm.getForm().findField("userOfficeFax").getEl().setDisabled(true);
                                detailForm.getForm().findField("userHomePostalCode").setDisabled(true);
                                detailForm.getForm().findField("userMobile").getEl().setDisabled(true);
                                detailForm.getForm().findField("userOfficePhone").setDisabled(true);
                                detailForm.getForm().findField("userHomePhone").setDisabled(true);
                                detailForm.getForm().findField("userNotes").setDisabled(true);
                                
                            }
                            if (json.otherreadony == 'true') {
                            }
                            if (json.mainreadony == 'true' && json.subordination == 'true' && json.otherreadony == 'true') {
                                Ext.getCmp("button").setDisabled(true);
                            }
                            //document.getElementById("button").style.display="none";
                        },
                        failure: function(){
                            Ext.Msg.alert('提示', '请先登录！');
                        }
                    });
                }
            }, new Ext.Panel({
                id: 'id1',
                name: 'id1',
                layout: 'form',
                html: '<a href="<%=basePath%>help/xxxg.jsp" target="_blank">帮助</a>'
            })]
        });
        
        
        // --------------- viewport --------------------
        
        var viewport = new Ext.Viewport({
            layout: 'fit',
            border: false,
            items: [detailForm]
        });
        
        // --------------- init --------------------
        
        // bind event
        detailForm.getForm().load({
            url: '<c:url value="/user/userInfo.do"/>',
            waitMsg: 'loading...',
            success: function(response, action){
                text = action.response.responseText;
                json = Ext.decode(text);
                Ext.get('imagePreview').dom.src = action.result.data.imageUrl;
                if (json.mainreadony == 'true') {
                    detailForm.getForm().findField("userRealName").setDisabled(true);
                    detailForm.getForm().findField("userCertificateType").setDisabled(true);
                    detailForm.getForm().findField("userCertificateNo").setDisabled(true);
                    detailForm.getForm().findField("userEmail").setDisabled(true);
                }
                if (json.subordination == 'true') {
                    detailForm.getForm().findField("userOfficeFax").getEl().setDisabled(true);
                    detailForm.getForm().findField("userHomePostalCode").setDisabled(true);
                    detailForm.getForm().findField("userMobile").getEl().setDisabled(true);
                    detailForm.getForm().findField("userOfficePhone").setDisabled(true);
                    detailForm.getForm().findField("userHomePhone").setDisabled(true);
                    detailForm.getForm().findField("userNotes").setDisabled(true);
                    
                }
                if (json.otherreadony == 'true') {
                }
                if (json.mainreadony == 'true' && json.subordination == 'true' && json.otherreadony == 'true') {
                    Ext.getCmp("button").setDisabled(true);
                }
                //document.getElementById("button").style.display="none";
            },
            failure: function(){
                Ext.Msg.alert('提示', '请先登录！');
            }
        });
        
        
        
        
    });
</script>
<%@ include file="/WEB-INF/views/common/footer.jsp" %>
